<template>
	<view style="padding: 20rpx;background-color: #fff;">
		<u--form labelWidth='80' labelPosition="left" :model="model1" :rules="rules" ref="uForm">
			<u-form-item label="客户名称" prop="userInfo.customerName" borderBottom ref="item1">
				<u--input v-model="model1.userInfo.customerName" placeholder="输入客户名称" border="none"></u--input>
				
			</u-form-item>
			<u-form-item label="驻场人员" prop="userInfo.phone" borderBottom ref="item1">
				<u--input v-model="model1.userInfo.phone" placeholder="输入驻场人员" border="none"></u--input>
			
			</u-form-item>
			<u-form-item label="招聘岗位" prop="userInfo.postName" borderBottom @click="showSex = true;" ref="item1">
				<u--input v-model="model1.userInfo.postName" disabled disabledColor="#ffffff" placeholder="输入招聘岗位"
					border="none"></u--input>
				<u-icon slot="right" name="arrow-right"></u-icon>
			</u-form-item>
			<u-form-item label="工作地点" prop="userInfo.address" borderBottom ref="item1">
				<u--input v-model="model1.userInfo.address" placeholder="输入工作地点" border="none"></u--input>
				
			</u-form-item>
			<u-form-item label="需求数量" prop="userInfo.demandQuantity" borderBottom ref="item1">
				<u--input v-model="model1.userInfo.demandQuantity" placeholder="输入需求数量" border="none"></u--input>
				
			</u-form-item>
			<u-form-item label="结算类型" prop="userInfo.settlementType" borderBottom ref="item1">
				<u--input v-model="model1.userInfo.settlementType" placeholder="输入结算类型" border="none"></u--input>
				
			</u-form-item>
			<u-form-item label="薪资范围" prop="userInfo.salaryRange" borderBottom ref="item1">
				<u--input v-model="model1.userInfo.salaryRange" placeholder="输入薪资范围" border="none"></u--input>
				
			</u-form-item>
			<u-form-item label="岗位职责" prop="userInfo.postDuty" borderBottom ref="item1">
				<u--textarea v-model="model1.userInfo.postDuty" placeholder="输入岗位职责" border="none"></u--textarea>
			</u-form-item>
			<u-form-item label="岗位要求" prop="userInfo.remark" borderBottom ref="item1">
				<u--textarea v-model="model1.userInfo.remark" placeholder="输入岗位要求" border="none"></u--textarea>
			</u-form-item>
			<u-form-item label="招聘状态" prop="userInfo.status" borderBottom ref="item1">
				<u--input v-model="model1.userInfo.status" placeholder="输入招聘状态" border="none"></u--input>
			</u-form-item>
			<u-form-item label="备注" prop="userInfo.remark" borderBottom ref="item1">
				<u--textarea v-model="model1.userInfo.remark" placeholder="输入备注" border="none"></u--textarea>
			</u-form-item>
		</u--form>
		<u-button style="margin-top: 10px;" type="primary" text="保存" @click="submitForm"></u-button>
		<u-action-sheet :show="showSex" :actions="actions" title="请选择性别" @close="showSex = false" @select="sexSelect">
		</u-action-sheet>
	
	
	</view>
</template>

<script>
	import {savePostManagement,updatePostManagement} from '@/api/zhiwei/zhiwei.js'
	export default {
		data() {
			return {
				showSex: false,
				type: '',
				model1: {
					userInfo: {},
				},
				actions: [{
						name: '男',
					},
					{
						name: '女',
					},
					{
						name: '保密',
					},
				],
				rules: {
					'userInfo.name': {
						type: 'string',
						required: true,
						message: '请填写姓名',
						trigger: ['blur', 'change']
					},
					'userInfo.phone': {
						type: 'string',
						required: true,
						message: '请填写手机号',
						trigger: ['blur', 'change']
					},
				},
			}
		},
		onLoad(options) {
			if (this.model1.userInfo) {
				this.showSex = false
			}
			console.log(options.renCaiInfo, "options")
			if (options.renCaiInfo) {
				this.model1.userInfo = JSON.parse(decodeURIComponent(options.renCaiInfo))
				console.log(this.model1)
				// this.type = options.type
			}
		},
		methods: {
			formSubmit: function(e) {
				console.log('form发生了submit事件，携带数据为：' + JSON.stringify(e.detail.value))
				var formdata = e.detail.value
				uni.showModal({
					content: '表单数据内容：' + JSON.stringify(formdata),
					showCancel: false
				});
			},
			submitForm() {
				if(this.model1.userInfo.id){
					savePostManagement(this.model1.userInfo).then(res=>{
						if(res.code == 200){
							uni.showToast({
								title: '成功', // 提示的内容
								icon: 'success', // 使用内置的成功图标
								duration: 2000 // 提示框显示的时间，单位为毫秒
							})
						}
					})
				}else{
					updatePostManagement(this.model1.userInfo).then(res=>{
						if(res.code == 200){
							uni.showToast({
								title: '成功', // 提示的内容
								icon: 'success', // 使用内置的成功图标
								duration: 2000 // 提示框显示的时间，单位为毫秒
							})
						}
					})
				}
				
			},
			sexSelect(e) {
				console.log(e)
				this.model1.userInfo.sex = e.name
				this.$refs.uForm.validateField('userInfo.sex')
			},
		}
	}
</script>

<style>
</style>